package com.pitop.user.ctrl;

import com.alibaba.fastjson.JSON;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.user.entity.UserInfo;
import com.pitop.user.service.UserInfoService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/userinfo")
@Slf4j
public class UserInfoCtrl {

    @Autowired
    private UserInfoService userInfoService;

    @Resource
    protected RedisUtils redisUtils;

    @ApiOperation(value = "用户根据ID获取信息", notes = "用户根据ID获取信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", dataType = "Long", required = true, paramType = "query")
    })
    @RequestMapping(value = "/getById", method = RequestMethod.GET)
    @ResponseBody
    public UserInfo getById(Long id) {
        UserInfo userInfoEntity = userInfoService.findById(id);
        redisUtils.set("user", JSON.toJSONString(userInfoEntity));
        log.debug(redisUtils.get("user").toString());
        return userInfoEntity;
    }


}
